package org.point.service.impl;

import java.io.Serializable;



import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.point.common.service.impl.BaseServiceImpl;
import org.point.common.util.DoPage;
import org.point.dao.ProductDao;
import org.point.dao.impl.ProductDaoImpl;
import org.point.domain.CreditsType;
import org.point.domain.Product;
import org.point.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * @ClassName: ProductServiceImpl  
 * @Description: TODO(商品信息业务实现类)  
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月23日 下午4:02:01  
 *
 */
@Service("productService")
public class ProductServiceImpl extends BaseServiceImpl<Product, Serializable> implements ProductService {
	
	@Autowired
	private ProductDao dao;

	public DoPage<Product> searchProForPage(DoPage<Product> page) {
		List<Product> records = dao.findProForMem(page);
		Integer totalRecords = dao.countProForMem(page);
		page.setList(records);
		page.setTotalRecords(totalRecords);
		return page;
	}

	public Product getPROByPROID(Map<String, Object> map) {
		Product record = dao.searchForPRO(map);
		return record;
	}

	public Integer insertPRO(Product record,String pt_code) {
		Integer result = 0;
		Map<String, Object> map = new HashMap<String, Object>();
		if(record.getProductId()!=null&&!"".equals(record.getProductId())){
			map.put("productId", record.getProductId());
			Integer del  = dao.delPro(map);
			Integer insert  = dao.insertPro(record);
			if(insert+del>1){
				result = 1;
		    }
		}else{
			record.setStatus(new Byte("1"));
			record.setProductId(pt_code);
			result = dao.insertPro(record);
		}
		return result;
	}

	public Integer deletePROs(Map<String, Object> map) {
		Integer result = dao.delProByids(map);
		return result;
	}
	
}
